// 用来存储公共的state
class Store {
  state: {
    mainWindow: Electron.CrossProcessExports.BrowserWindow | null;
    readyWindow: Electron.CrossProcessExports.BrowserWindow | null;
    startTray: Electron.CrossProcessExports.Tray | null;
    stopTray: Electron.CrossProcessExports.Tray | null;
    recordStatus: 'start' | 'pause' | 'recording';
  };

  static _instance: any;
  constructor() {
    this.state = {
      mainWindow: null,
      startTray: null,
      stopTray: null,
      recordStatus: 'start',
      readyWindow: null
    };
    if (new.target !== Store) {
      return;
    }
    if (!Store._instance) {
      Store._instance = this;
    }
    return Store._instance;
  }

  /**
   * 设置state中的数据
   * @param {object} 传入需要修改的state数据 eg: {a: 1, b: 2}
   */
  setState(obj) {
    // 判断obj是否是对象
    if (obj instanceof Object) {
      this.state = {
        ...this.state,
        ...obj
      };
    } else {
      throw new TypeError('param must be an object');
    }
  }
}
export default new Store();
